<template>
	<view class="subordinatePage">
		<!-- title 栏 -->
		<view class="titleBox flex-r-a-c">
			<view class="list">
				<view class="text">姓名</view>
			</view>
			<view class="list flex-r-c-c" @tap.stop="isLevelBtn = true">
				<view class="text" style="margin-right: 10rpx;">{{leveText == '' ? '级别' : leveText}}</view>
				<u-icon name="arrow-down" color="#FFFFFF" size="20"></u-icon>
			</view>
			<view class="list flex-r-c-c" @tap.stop="sortBtn(1)">
				<view class="text">人数</view>
				<image src="/static/icon/px.png" mode="widthFix"></image>
			</view>
			<view class="list flex-r-c-c" @tap.stop="sortBtn(2)">
				<view class="text">销售额</view>
				<image src="/static/icon/px.png" mode="widthFix"></image>
			</view>
		</view>
		
		<!-- 列表数据 -->
		<view class="listData flex-r-a-c" v-for="(item,index) in list" :key="index">
			<view class="list flex-r-c-c">
				<view class="text">{{item.nickname}}</view>
			</view>
			<view class="list flex-r-c-c">
				<view class="text">{{item.level}}</view>
			</view>
			<view class="list flex-r-c-c">
				<view class="text">{{item.num}}</view>
			</view>
			<view class="list flex-r-c-c">
				<view class="text">{{item.price}}</view>
			</view>
		</view>
		
		<!-- 级别选择 -->
		<u-picker mode="selector" v-model="isLevelBtn" :range="idcrodeList" range-key="rank" @confirm="levelBtn"></u-picker>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageData: {}, // 页面数据
				type: null, // type = 1 代表 分销中心, type = 2 代表 代理中心
				list: [] ,// 列表数据
				sort: 1 , // 人数和销售额排序
				idcrodeList: [],
				leveId: '', // 级别id
				leveText: '', // 级别名称
				isLevelBtn: false, // 级别
				status: 'desc', // desc 是从高到低   asc 是从低到高
			};
		},
		onLoad(el) {
			this.pageData = el
			this.type = el.type  // type = 1 代表 分销中心, type = 2 代表 代理中心
			this.AgentIdentityList() // 获取级别的列表
			el.type == 1 ? this.getDistributionList() : this.getAgentList()
		},
		methods:{
			// 获取级别的列表
			AgentIdentityList(){
				let that = this
				that.$api.getAgentGrade().then(res => {
					console.log(res)
					that.idcrodeList = res.data.data
					that.idcrodeList.push({id: 1, rank: '分享人'},{id: '', rank: '全部'})
				})
			},
			// 代理 下级业绩
			getAgentList(){
				let that = this
				that.$api.agent_lower({id: that.pageData.id, type: that.sort, idcrode: that.leveId, status: that.status}).then(res => {
					console.log(res)
					that.list = res.data.data
				})
			},
			// 分销 下级业绩
			getDistributionList(){
				let that = this
				
			},
			// 级别选择
			levelBtn(e){
				let that = this
				that.leveId = that.idcrodeList[e].id
				that.leveText = that.idcrodeList[e].rank
				that.type == 1 ? this.getDistributionList() : this.getAgentList()
			},
			// 排序
			sortBtn(e){
				let that = this
				that.sort = e
				that.status == 'desc' ? that.status = 'asc' : that.status = 'desc'
				that.type == 1 ? this.getDistributionList() : this.getAgentList()
			}
		}
	}
</script>

<style lang="less">
	.subordinatePage{
		width: 95vw;
		margin: 0 auto;
		.titleBox{
			width: 100%;
			height: 84rpx;
			background-color: #45806E;
			.list{
				width: 25%;
				text-align: center;
				color: #FFFFFF;
				font-size: 28rpx;
				font-weight: 500;
				image{
					width: 18rpx;
					margin-left: 10rpx;
				}
			}
		}
		.listData{
			width: 100%;
			height: 96rpx;
			background-color: #FFFFFF;
			.list{
				width: 25%;
				height: 100%;
				text-align: center;
				color: #4B4B4B;
				font-size: 28rpx;
				font-weight: 500;
				border-top: 1px solid #F2F2F2;
			}
		}
	}
</style>
